<?php
/**
 * 修复设备管理菜单URL
 */

// MySQL连接配置
$host = '113.44.136.17';
$port = '3306';
$database = 'qiandao';
$username = 'qiandao';
$password = 'NGbks3HWx5PhSxDX';

try {
    $pdo = new PDO("mysql:host={$host};port={$port};dbname={$database};charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "=== 修复设备管理菜单URL ===\n\n";
    
    // 使用 ThinkAdmin 推荐的 ?s= 路由方式，避免多应用路由冲突
    // 更新设备列表菜单的URL
    $stmt = $pdo->prepare("UPDATE system_menu SET url = '?s=checkin/device/index' WHERE node = 'checkin/device/index'");
    $stmt->execute();
    echo "✓ 更新设备列表菜单URL\n";

    // 更新设备统计菜单的URL
    $stmt = $pdo->prepare("UPDATE system_menu SET url = '?s=checkin/device/statistics' WHERE node = 'checkin/device/statistics'");
    $stmt->execute();
    echo "✓ 更新设备统计菜单URL\n";

    // 更新测试页面菜单的URL
    $stmt = $pdo->prepare("UPDATE system_menu SET url = '?s=checkin/test/index' WHERE node = 'checkin/test/index'");
    $stmt->execute();
    echo "✓ 更新测试页面菜单URL\n";
    
    // 检查更新结果
    echo "\n当前设备相关菜单:\n";
    $stmt = $pdo->query("
        SELECT id, title, node, url, status 
        FROM system_menu 
        WHERE node LIKE 'checkin/device%' OR node LIKE 'checkin/test%'
        ORDER BY id
    ");
    $menus = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    foreach ($menus as $menu) {
        $status = $menu['status'] == 1 ? '启用' : '禁用';
        echo "  ID:{$menu['id']} {$menu['title']} (node:{$menu['node']}, url:{$menu['url']}, 状态:{$status})\n";
    }
    
    echo "\n✅ 菜单URL修复完成！\n";
    echo "\n请刷新浏览器，现在应该能看到设备管理菜单了。\n";
    
} catch (PDOException $e) {
    echo "❌ 数据库错误: " . $e->getMessage() . "\n";
}
?>
